﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using ZFCNew.Controls;
using ZFCNew.Views;
using ZFCNew.Code;

namespace ZFCNew
{
    public partial class About : Page
    {
        public About()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(About_Loaded);
        }

        void About_Loaded(object sender, RoutedEventArgs e)
        {
            RBGeneral.IsChecked = true;
        }

        //// Executes when the user navigates to this page.
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //    foreach (var nav in NavHolder.Children)
        //    {
        //        var navBtn = (RadioButton)nav;
        //        if (navBtn.Tag.ToString() == e.Uri.ToString())
        //        {
        //            if (navBtn.IsChecked != true) navBtn.IsChecked = true;
        //            break;
        //        }
        //    }
        //    base.OnNavigatedTo(e);
        //}


        private void NavigationTabSelected(object sender, RoutedEventArgs e)
        {
            //NavigationService.StopLoading();
            var c = (Control)sender;
            // NavigationService.Navigate(new Uri(c.Tag.ToString(), UriKind.Relative));
            VisualStateManager.GoToState(this, c.Name + "State", true);
        }

        private void ShowFeedback(object sender, System.Windows.RoutedEventArgs e)
        {
            var feedbackWindow = new ZfcWindow();
            feedbackWindow.VerticalAlignment = VerticalAlignment.Top;
            feedbackWindow.Margin = new Thickness(0, 170, 0, 0);
            var fb = new Feedback();
            feedbackWindow.Content = fb;
            fb.CancelButton.Click += (s, a) => feedbackWindow.DialogResult = false;
            fb.OKButton.Click += (s, a) => feedbackWindow.DialogResult = true;
            feedbackWindow.Show();
        }

        private void ShowFaq(object sender, System.Windows.RoutedEventArgs e)
        {
            this.RBFaq.IsChecked = true;
        }

        private void PostToFacebook(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!FacebookHelper.IsLoggedIn)
            {
                MainPage.NotificationPop.SetMessage
                    (
                    new NotificationData
                    {

                        Message = "Uh-Oh! You need to connect with facebook to use this feature."
                    }
                    );
                MainPage.NotificationPop.Show();
            }
            else
            {
                OpenPostFavTeamWindow();
            }
        }

        private void OpenPostFavTeamWindow()
        {
            var sft = new FacebookMessage();
            var win = new ZfcWindow();
            win.VerticalAlignment = VerticalAlignment.Top;
            win.Margin = new Thickness(0, 70, 0, 0);
            win.Style = (Style)Application.Current.Resources["ZfcChildWindowFlatStyle"];

            win.Content = sft;
            win.Show();

             sft.OKButton.Click += (s, e) =>
                                      {
                                          if (!string.IsNullOrEmpty(sft.Message))
                                          {
                                              Post(sft.Message);
                                              win.DialogResult = true;
                                          }
                                      };
            sft.CancelButton.Click += (s, e) => win.DialogResult = false;

        }

        private void Post(string message)
        {
            string caption = "Zakumi fan club";
            string description = "\nZFC is a hobby website developed in the theme of FIFA world cup 2010. You can get results, schedules, news and lot more ...";
            FacebookHelper.PostMessage(message, description, caption);
        }
    }
}
